<template>
<div id="menu">
  <a-layout id="components-layout-demo-custom-trigger">
    <a-layout-sider
      :trigger="null"
      collapsible
      v-model="collapsed"
    >
      <div class="logo" >Cloudy</div>
       <a-menu
        mode="inline"
        theme="dark"
        :inlineCollapsed="collapsed"
      >
        <a-sub-menu v-for="menu in menuList" :key="menu.key">
          <span slot="title"><a-icon :type="menu.icon" /><span>{{menu.name}}</span></span>
          <a-menu-item :key="item.key" v-for="item in menu.children" @click="menuClick(item)">{{item.name}}</a-menu-item>
        </a-sub-menu>
        <a-menu-item key="tool" @click="menuClick({key: 'tool', name: '工具'})">
          <a-icon type="appstore" />工具
        </a-menu-item>
      </a-menu>
    </a-layout-sider>

    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <a-icon
          class="trigger"
          :type="collapsed ? 'menu-unfold' : 'menu-fold'"
          @click="()=> collapsed = !collapsed"
        />
        &nbsp;
        <span style="font-size: 24px;">{{activeMenu.name}}</span>
      </a-layout-header>

      <a-layout-content :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }">
        <router-view/>
      </a-layout-content>
    </a-layout>
  </a-layout>
  <a-icon type="up-circle" @click="toTop" title="返回顶部" style="position: fixed; right: 30px; bottom: 30px; font-size: 30px; cursor: pointer;"/>
</div>
</template>
<script>
export default {
  name: 'myMenu',
  data(){
    return {
      collapsed: false,
      activeMenu: {},
      menuList: [
        {name: 'UI 组件', key: 'UI', icon: 'mail', children: [
          {name: '时间轴', key: 'timeline'},
          {name: '树组件', key: 'tree'},
          {name: '日历组件', key: 'calendar'}
        ]},
        {name: '前端杂记', key: 'js', icon: 'mail', children: [
          {name: 'vue之render基本书写方法', key: 'vueReader'},
          {name: 'Token认证来龙去脉', key: 'token'},
          {name: '本地存储', key: 'localStorage'},
          {name: '常用函数汇总', key: 'functions'},
          {name: 'vip视频解析', key: 'videoParsing'},
        ]},
        {name: '数据结构与算法', key: '算法', icon: 'appstore', children: [
          {name: '排序', key: 'sort'},
          {name: '缓存', key: 'dnCache'},
          {name: '队列', key: 'Queue'},
          {name: '优先队列', key: 'PriorityQueue'},
          {name: '单向链表', key: 'LinkedList'},
          {name: '双向链表', key: 'DoublyLinkedList'},
          {name: '循环链表', key: 'CircularLinkedList'},
        ]}
      ]
    }
  },
  methods: {
    menuClick(item) {
      this.activeMenu = item
      this.$router.replace({ path: '/' + item.key })
    },
    toTop(){
      window.scrollBy(0,-window.scrollY)
    }
  }
}
</script>
<style scoped>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color .3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255,255,255,.2);
  margin: 16px;
  line-height: 32px;
  color: #fff;
  text-align: center;
}
</style>